﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DAO;

namespace TAM_SPORT
{
    public partial class FrmImportReport : TAM_SPORT.FormBase
    {
        private ImportDao imDao;
        public FrmImportReport()
        {
            InitializeComponent();
            imDao = new ImportDao();
            cbxKind.SelectedIndex = 0;
            loadGrid();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            loadGrid();
        }
        private void loadGrid()
        {
            DataTable table = imDao.getImportReport(dtFrom.Value, dtTo.Value, cbxKind.SelectedIndex);
            dtgResult.Rows.Clear();
            if (table != null && table.Rows.Count > 0)
            {
                foreach (DataRow row1 in table.Rows)
                {
                    int i = dtgResult.Rows.Add();
                    dtgResult.Rows[i].Cells[0].Value = i + 1;
                    dtgResult.Rows[i].Cells[1].Value = DateTime.Parse(row1["IMPORT_DATE"].ToString()).ToString("dd/MM/yyyy");
                    dtgResult.Rows[i].Cells[2].Value = row1["NAME"].ToString();
                    dtgResult.Rows[i].Cells[3].Value = row1["UNIT_NAME"].ToString();
                    dtgResult.Rows[i].Cells[4].Value = Convert.ToDouble(row1["QUANTITY"]).ToString("#,###.##");
                    dtgResult.Rows[i].Cells[5].Value = Convert.ToDouble(row1["PRICE"]).ToString("#,###.##");
                    dtgResult.Rows[i].Cells[6].Value = Convert.ToDouble(row1["TOTAL"]).ToString("#,###.##");
                    if (i % 2 == 1)
                    {
                        dtgResult.Rows[i].DefaultCellStyle.BackColor = Color.LightCyan;
                    }
                }
            }
        }
    }
}
